﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PRET.ReportControlLib.Controls
{
    public partial class SetYearPanelSim : UserControl
    {
        public event ShowProLineStandbyEventHandle showReportEvent;

        private readonly static int StartYear = DateTime.Now.Year;
        public SetYearPanelSim()
        {
            InitializeComponent();
            InitializeYears();
        }

        public void EnableControls(bool sign)
        {
            this.yearCombox.Enabled = sign;
            this.reportViewBtn.Enabled = sign;
        }

        public DateTime GetSelectedYear
        {
            get
            {
                string year = string.Format("{0}-01-01 00:00:00", this.yearCombox.SelectedItem.ToString());
                return DateTime.Parse(year);
            }
        }

        private bool IsCorrectYear()
        {
            if (this.yearCombox.SelectedItem == null)
                return false;
            return true;
        }

        private void InitializeYears()
        {
            int count = DateTime.Now.Year - StartYear;
            List<string> ds = new List<string>();
            for(int i = 0; i <= count; i++)
            {
                int year = StartYear + i;
                ds.Add(year.ToString());
            }
            this.yearCombox.DataSource = ds;
        }

        private void reportViewBtn_Click(object sender, EventArgs e)
        {
            if (showReportEvent != null)
            {
                if (!this.IsCorrectYear())
                {
                    MessageBox.Show("请从列表中选择正确的年份！", "操作错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                ShowProLineStandbyEventArgs eventArg = new ShowProLineStandbyEventArgs();
                eventArg.StartYear = this.GetSelectedYear;
                showReportEvent(this, eventArg);
            }
        }
    }

    public delegate void ShowProLineStandbyEventHandle(object sender, ShowProLineStandbyEventArgs args);

    public class ShowProLineStandbyEventArgs : EventArgs
    {
        public ShowProLineStandbyEventArgs()
        { }
        private DateTime startYear;
        public DateTime StartYear
        {
            get { return startYear; }
            set { startYear = value; }
        }
    }
}
